<template>
  <div>
    <div class="i-layout-page-header">
      <div class="i-layout-page-header">
        <span class="ivu-page-header-title">{{ $route.meta.title }}</span>
      </div>
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <Form
      		  ref="roleData"
      		  :model="roleData"
      		  :label-width="labelWidth"
      		  :label-position="labelPosition"
      		  @submit.native.prevent
      		>
      		  <Row type="flex" :gutter="24">
      		    <Col v-bind="grid">
      		      <FormItem label="分类名称：" label-for="keywords">
      		        <Input
      		          search
      		          enter-button
      		          placeholder="请输入分类名称关键字"
      		          v-model="groupFrom.keywords"
      		          @on-search="userSearchs"
      		        />
      		      </FormItem>
      		    </Col>
      		  </Row>
      		  <Row type="flex">
      			<Col v-bind="grid">
      			  <Button type="primary" icon="md-add" @click="add">新增</Button>
      			</Col>
      		  </Row>
      </Form>
      <Table
        :columns="columns1"
        :data="groupLists"
        ref="table"
        class="mt25"
        :loading="loading"
        highlight-row
        no-userFrom-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
      >
	    <template slot-scope="{ row, index }" slot="id">
	      {{index+1}}
	    </template>
	    <template slot-scope="{ row, index }" slot="status">
	      <span v-if="row.status == 0">启用</span>
	      <span v-else>停用</span>
	    </template>
	    <template slot-scope="{ row, index }" slot="action">
	      <a @click="edit(row.id)">修改</a>
	      <Divider type="vertical" />
	      <a  @click="del(row)">删除</a>
	    </template>
      </Table>
      <div class="acea-row row-right page">
        <Page :total="total" show-elevator show-total @on-change="pageChange" :page-size="groupFrom.limit" />
      </div>
    </Card>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { ListApi, formAddApi } from '@/api/petkinsectcate';
export default {
  name: 'user_group',
  data() {
    return {
      grid: {
        xl: 7,
        lg: 7,
        md: 12,
        sm: 24,
        xs: 24,
      },
      loading: false,
      columns1: [
		{
	      title: '序号',
	      align: 'center',
	      slot: 'id',
	      width: 100,
	    },
		{
	      title: '名称',
	      align: 'center',
	      key: 'name',
	      minWidth: 100,
	    },
		{
	      title: '描述',
	      align: 'center',
	      key: 'remark',
	      minWidth: 200,
	    },
		{
	      title: '状态',
	      align: 'center',
	      slot: 'status',
	      minWidth: 100,
	    },
        {
          title: '操作',
          slot: 'action',
          fixed: 'right',
          minWidth: 120,
        },
      ],
	  roleData: {
	    is_show: '',
	    keyword: '',
	  },
      groupFrom: {
        page: 1,
        limit: 15,
		keywords:''
      },
      groupLists: [],
      total: 0,
    };
  },
  computed: {
    ...mapState('media', ['isMobile']),
    labelWidth() {
      return this.isMobile ? undefined : 75;
    },
    labelPosition() {
      return this.isMobile ? 'top' : 'left';
    },
  },
  created() {
    this.getList();
  },
  methods: {
    // 添加
    add() {
      this.$modalForm(formAddApi(0)).then(() => this.getList());
    },
    // 列表
    getList() {
      this.loading = true;
      ListApi(this.groupFrom)
        .then(async (res) => {
          let data = res.data;
          this.groupLists = data.list;
          this.total = data.count;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$Message.error(res.msg);
        });
    },
    pageChange(index) {
      this.groupFrom.page = index;
      this.getList();
    },
    // 修改
    edit(id) {
      this.$modalForm(formAddApi(id)).then(() => this.getList());
    },
    // 删除
    del(row, tit, num) {
      let delfromData = {
        title: tit,
        num: num,
        url: `petkinsectcate/del/${row.id}`,
        method: 'DELETE',
        ids: '',
      };
      this.$modalSure(delfromData)
        .then((res) => {
          this.$Message.success(res.msg);
          this.groupLists.splice(num, 1);
          this.getList();
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
	userSearchs(){
		this.groupFrom.page = 1;
		this.getList();
		console.info(this.formValidate)
	}
  },
};
</script>

<style scoped lang="stylus"></style>
